package model.user;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.SelectItem;
import model.beans.DirectedGraphBean;
import model.beans.RouterBean;

/**
 *
 * @author Danon
 */
@ManagedBean @SessionScoped
public class RouterExplorerBean implements Serializable {
    public final long serialVersionID = 1L;
    private RouterBean currentRouter;
    private List<SelectItem> routersSelectItmes;
    
    
    public RouterExplorerBean() {
        routersSelectItmes = new ArrayList<>();
    }
    
    public List<SelectItem> getRouterSelectItems() {
        if(!routersSelectItmes.isEmpty())
            return routersSelectItmes;
        List<RouterBean> lst = listRouters();
        for(RouterBean r : lst) {
            SelectItem item = new SelectItem(r, r.getName());
            routersSelectItmes.add(item);
        }
        return routersSelectItmes;
    }
    
    public List<RouterBean> listRouters() {
        return DirectedGraphBean.getVertices(100);
    }
    
    public String changeRouter(RouterBean r) {
        currentRouter = r;
        return "explorer?faces-redirect=true";
    }
    
    public RouterBean getCurrentRouter() {
        return currentRouter;
    }
    
    public void setCurrentRouter(RouterBean router) {
        currentRouter = router;
    }
}
